<template>
<div class="attention-wrap">
    <G_header title="我的关注" />
    <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="getData">
        <div class="list" v-for=" (item,index) in store" :key="index" @click="getstore(item)"  >
            <van-row class="item"  type="flex" justify="space-between">
                <van-col class="text-center" offset="1" span="3">
					<van-image width="50" height="50" :src=" item.store.avatar || 'https://img.yzcdn.cn/vant/cat.jpeg'" />
                </van-col>
                <van-col span="15" class="van-multi-ellipsis--l2 store-title">{{ item.store.title }}</van-col>
                <van-col class="text-center store-tool" span="6">
                    <van-button size="mini" @click.stop="closeLike(item.id)" type="danger">取消关注</van-button>
                </van-col>
            </van-row>
        </div>
    </van-list>

</div>
</template>

<script>
import { Toast } from 'vant';
export default {
    name: 'Attention',
    data() {
        return {
			store: [],
			finished: false,
			loading: true,
			c_page: null
        }
    },
    created() {
        this.getData()
    },
    methods: {
        async getData() {
			Toast.loading({
				message: '加载中...',
				forbidClick: true,
				loadingType: 'spinner'
			});
            let params = {
				token: sessionStorage.getItem('token'),
				page: this.c_page + 1 || 1
            }
            const r = await this.axios.get('/api/store/user/favorite/list/store', {
                params
			})
			Toast.success('成功');
			this.c_page = r.data.data.current_page;
			
			if(r.data.data.current_page == 1){
				this.store = r.data.data.data;
			}else {
				this.store = [...this.store,...r.data.data.data];
			}
			this.loading = false;
			if(this.c_page = r.data.data.last_page){
				this.finished = true;
			}
        },
        async closeLike(id) {
			Toast.loading({
				message: '加载中...',
				forbidClick: true,
				loadingType: 'spinner'
			});
			let params = {
				token: sessionStorage.getItem('token'),
            }
			const r = await this.axios.get('/api/store/user/favorite/delete/'+id, {
				params
			})
			this.c_page = null;
			this.getData();
			Toast.success(r.data.message);
		},
		getstore(item){
			this.$router.push({name:'store',path:'../store'})
			this.global.state.productMerchant_store = item.store;
		},

    }
}
</script>

<style lang="less" scoped>
.attention-wrap {
    .list {
        .item {
            margin-top: .25rem;
            background-color: white;
            padding: .25rem;

            .store-title {
                line-height: 25px;
                padding-left: 0.7692rem;
            }

            .store-tool {
                line-height: 50px;
            }
        }

    }

}
</style>
